﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using GONES.IBLL;
using GONES.Tools.Common;
using GONES.Model;

public partial class Console_System_UserRights_UserRoleSet : CPage
{
    public string UserId { get; set; }
    public string RoleId { get; set; }
    public string UserName { get; set; }
    public string EmployeeName { get; set; }

    protected void Page_Load(object sender, EventArgs e)
    {
        UserId = Request.QueryString["id"].ToString();
        var userManager = AppContext.GetObject("S_UsersManager") as IS_UsersManager;
        var empManager = AppContext.GetObject("S_EmployeesManager") as IS_EmployeesManager;
        GONES.Model.S_Users user = new GONES.Model.S_Users();
        user = userManager.Get(UserId);
        if (user != null)
        {
            UserName = user.UserName;
            if(user.EmployeeId!=null)
            {
                EmployeeName = empManager.Get(user.EmployeeId).EmployeeName;
            }
        }
    }

    public string GetCheckBox()
    {
        string chkHtml = "";
        var roleManager = AppContext.GetObject("S_RoleManager") as IS_RoleManager;
        var roleuserManager = AppContext.GetObject("S_UserRoleManager") as IS_UserRoleManager;
        IList<DataFilter> dataFilters = new List<DataFilter>();
        long recordcount=0;
        IList<S_Role> rolesList = roleManager.List(dataFilters, 1, 100, ref recordcount);
        IList<S_UserRole> userrolesList = roleuserManager.GetUserRolesList(UserId);
        string uroleidstr = "";
        foreach (var roles in userrolesList)
        {
            uroleidstr += roles.RoleId;
        }
        for (int i = 0; i < rolesList.Count; i++)
        {
            if (!uroleidstr.Contains(rolesList[i].ID))
            {
                chkHtml += string.Format(" <input type=\"checkbox\" size=30 name=box  value=\"{0}\">{1}</input>",
                    rolesList[i].ID, rolesList[i].RoleName);
            }
            else
            {
                chkHtml += string.Format(" <input type=\"checkbox\" checked=\"checked\" size=30 name=box  value=\"{0}\">{1}</input>",
                                  rolesList[i].ID, rolesList[i].RoleName);
            }
        }
        return chkHtml;
    }
}